﻿/*
 * Copyright 2009 José David Tuero Rodríguez

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 * */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace AtmosCreator
{
    /// <summary>
    /// Class used to select a game
    /// </summary>
    public partial class FrmSelectGame : Form
    {

        /// <summary>
        /// Form father of this
        /// </summary>
        private Form _father;


        /// <summary>
        /// Localizer
        /// </summary>
        Localizer _localizer;

        /// <summary>
        /// Business class
        /// </summary>
        GamesControl _gamesControl;


        /// <summary>
        /// Constructor, reads the available games and create the dafault noname if no game is found
        /// </summary>
        /// <param name="father">The father form of this</param>
        /// <param name="localizer">Localizer</param>
        public FrmSelectGame(Form father, Localizer localizer)
        {
            _father = father;
            _localizer = localizer;
            InitializeComponent();
            localizer.LocalizeForm(this);
            _gamesControl = new GamesControl();
            try
            {
                string[] games = _gamesControl.GetGames();
                for (int i = 0; i < games.Length; i++)
                {
                    cmbSelectGame.Items.Add(games[i].ToLower());
                }
                cmbSelectGame.SelectedIndex = 0; 
            }
            catch (Exception ex)
            {
                MessageBox.Show(localizer.GetError("ErrorGetGames"));
                throw ex;
            }
        }

        /// <summary>
        /// When closing we make visible the father form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmSelectGame_FormClosed(object sender, FormClosedEventArgs e)
        {
            _father.Visible = true;
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            _gamesControl.CheckGameDirectory(cmbSelectGame.Items[cmbSelectGame.SelectedIndex].ToString());
            ((FrmMain)_father).GameSelected = cmbSelectGame.Items[cmbSelectGame.SelectedIndex].ToString();
            this.Close();
        }

 
    }
}
